<!--
 * @Author: 哈尔滨大拐 3181845089@qq.com
 * @Date: 2022-07-20 09:50:20
 * @LastEditors: 哈尔滨大拐 3181845089@qq.com
 * @LastEditTime: 2022-07-20 15:39:55
 * @FilePath: \mygit\实验\25-正则表达式.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function execReg(reg, str) {
            var result = reg.exec(str)
            console.log(result);
        }


        // reg = /c{1,}/;
        // reg = /c{0}/;
        // reg = /c{1,}?/;
        // reg = /^c/;
        // reg = /v$/;
        // str = 'cccctiv';
        // execReg(reg, str);

        // 匹配数字
        // let re = /\d+$/
        // let re = /[0-9]+$/
        // let str = 'adfjhsf302'
        // execReg(re,str)


        // 统一空格数
        // let str = "蓝 色   理            想"
        // let str2 = str.replace(/\s+/g, " ")
        // console.log(str);
        // console.log(str2);


        // 判断字符串是否由数字组成
        //     function isDigital(str){
        //         return !/\D/.test(str)
        //     }

        //    console.log(isDigital("123456"));
        //    console.log(isDigital("123456ad"));


        //匹配电话号
        // let reg = /\d{3,4}-\d{7,8}(-\d{3,4}){0,1}/
        // let str = "0451-12345678-1234"
        // execReg(reg,str)

        // let reg = /0?(13|15)\d{9}/
        // let str = "013012345678"
        // let str1 = "0130123456616"
        // execReg(reg, str)
        // execReg(reg, str1)

        // 删除首位空格
      
        
        function trim(str) {
            return str.replace(/^\s*|\s*$/, "")
        }
        console.log(trim("   ab c   "));
    </script>
</body>

</html>